package com.ky.manage.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ky.manage.R;
import com.ky.manage.model.DocInfo;
import com.ky.manage.utils.ImageLoader.ImageLoaderUtils;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * 图片显示 adapter
 */
public class PicShowAdapter extends BaseQuickAdapter<DocInfo, BaseViewHolder> {
    private List<DocInfo> list;

    public PicShowAdapter(int layoutId, List<DocInfo> list) {
        super(layoutId, list);
        this.list = list;
    }

    public void setData(List<DocInfo> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder , DocInfo info) {
        Context context = baseViewHolder.itemView.getContext();
        ImageView picIv = baseViewHolder.getView(R.id.img_iv);
        // 图片
        if (null != info && !TextUtils.isEmpty(info.docUrl)) {
            ImageLoaderUtils.loadImage(context, info.docUrl, picIv);
        } else {
            picIv.setImageDrawable(context.getDrawable(R.mipmap.default_bg));
        }
    }
}
